package com.zmc.dynamic.common;


import com.zmc.dynamic.common.exception.BaseException;
import lombok.Data;

import java.time.Instant;

@Data
public class ErrorResponse {

    private int code;
    private int status;
    private String message;
    private String path;
    private Instant timestamp;

    public ErrorResponse() {
    }

    public ErrorResponse(BaseException ex, String path) {
        this(ex.getError().getCode(), ex.getError().getStatus().value(), ex.getError().getMessage(), path);
    }

    public ErrorResponse(int code, int status, String message, String path) {
        this.code = code;
        this.status = status;
        this.message = message;
        this.path = path;
        this.timestamp = Instant.now();
    }

    @Override
    public String toString() {
        return"ErrorReponse{" +
                "code=" + code +
                ", status=" + status +
                ", message='" + message + '\'' +
                ", path='" + path + '\'' +
                ", timestamp=" + timestamp +
                '}';
    }
}
